<?php
namespace Admin\Controller; 
use Org\Util;
use Org\GrLBS;
/**
 * Description of LbsController
 *
 * @author Myron
 */
class LbsAppController extends AdminController {
    //put your code here
    public function index(){
        $name = I('name');
        $map['name'] = array('like', '%' . (string) $name . '%');
        $list = $this->lists('lbs_application', $map);
        int_to_string($list); 
        $this->assign('_list', $list);
        $this->meta_title = '应用管理';
        $this->display(); 
    }
    
    /*添加
    * @author 曹梦龙 <138888611@qq.com>
    */

    public function add($name=''){
         if(IS_POST){
            $gr_lbs_application = array( 
                'name'=>$name,
                'appkey'=>md5(NOW_TIME),
                'STATUS'=>1,
                'createat'=>NOW_TIME, 
                'delflag'=>0,
                ); 
                $id = M('lbs_application')->add($gr_lbs_application);
                if (!$id) {
                        $this->error('添加失败！');
                } else {
                        $this->success('添加成功！', U('index'));
                };
         }else{
            $this->display();
         }
     }
                                      
        /** 
        * 状态修改
        * @author 曹梦龙 <138888611@qq.com>
        */
        public function changeStatus($method = null, $id) {
           $id = is_array($id) ? implode(',', $id) : $id;
           if (empty($id)) {
               $this->error('请选择要操作的数据!');
           }
           $map['id'] = array('in', $id); 
           switch (strtolower($method)) {
               case 'forbid':
                   $this->forbid('lbs_application', $map);
                   break;
               case 'resume':
                   $this->resume('lbs_application', $map);
                   break;
               case 'delete':
                   $this->delete('lbs_application', $map);
                   break;
               default:
                   $this->error('lbs_application');
           }
        }
               
        /** 
        * 演示
        * @author 曹梦龙 <138888611@qq.com>
        */
        public function demo(){
            $GeoUtils=new GrLBS\GeoUtils();
            $result=$GeoUtils->isPointInArea('a5107dfd89e6d3baf2610e009bd0d891',2,119.438151,32.391171);
            $this->assign('result',$result); 
            $this->display();
        }
}
